<?php
/**
 * @license    GNU/GPL
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.application.component.view');
jimport('joomla.html.pagination');

/**
 * HTML View class for the CommunalMeals Component Admin
 *
 */

class CommunalMealsViewEventGroups extends JView
{
	function display($tpl = null)
	{
		global $option, $mainframe;
        
        // Handle pagination
        $limit = JRequest::getVar('limit', $mainframe->getCfg('list_limit'));
		$limitstart = JRequest::getVar('limitstart', 0);
		$total = CMeals::countEventGroups();
		$pageNav = new JPagination($total, $limitstart, $limit);
        
		// Get data from model
		$eventGroupList = CMeals::readEventGroupList("description desc", $limitstart, $limit);
        
		foreach ($eventGroupList as $eventGroup) {
			// Attach event list
			$eventGroup->eventList = CMeals::readEventList($eventGroup->id);
			// Attach crew list
			$eventGroup->crewList = CMeals::readCrewList($eventGroup->id);
			// Attach can-delete flag
			$eventGroup->canDelete = !(CMeals::eventGroupHasProcessingEvents($eventGroup->id));
		}
		
		// Toolbar
		JToolBarHelper::title( JText::_('EVENT_GROUP_ADMIN_TITLE'), 'generic.png' );
        JToolBarHelper::deleteList(JText::_('EVENT_GROUP_DELETE_CONFIRMATION'), 'remove');
        //JToolBarHelper::editListX();
        JToolBarHelper::addNewX();
        JToolBarHelper::preferences("com_communalmeals");
        
		// Pass data to template
        $this->assignRef( 'eventGroupList', $eventGroupList );
		$this->assignRef( 'pageNav', $pageNav );
        $this->assignRef( 'option', $option );
		
		parent::display($tpl);
	}
}